
/**
 * @typedef CreateFolder
 * @property {string} name.required -文件夹名称
 * @property {string} isPrivate.required -是否私有
 */

/**
 * @typedef UpdateFolder
 * @property {string} id.required -文件夹id
 * @property {string} name.required -文件夹名称
 * @property {string} isPrivate.required -是否私有
 */

/**
 * @typedef UpdateFolderSort
 * @property {array} ids.required -文件夹排序id列表
 */

/**
 * @typedef DeleteFolder
 * @property {string} id.required -文件夹id
 */

const express = require('express')
const router = express.Router()
const auth = require('@/middleware/auth.middleware')
const handlerValidate = require('@/middleware/handlerValidate.middleware')
const siteFolderController = require('@/controllers/site_folder.controller')
const { createFolderShema } = require('@/middleware/validators/siteFolderValidator.middleware')

/**
 * 查询用户文件夹列表
 * @route GET /site/folder/list
 * @group 站点文件夹管理
 * @param {string} userId.query.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @security JWT
 */
router.get('/list', siteFolderController.findFolders)

/**
 * 用户创建站点文件夹
 * @route POST /site/folder/create
 * @group 站点文件夹管理
 * @param {CreateFolder.model} createFolder.body.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @security JWT
 */
router.post('/create', auth(), createFolderShema, handlerValidate(siteFolderController.createFolder))

/**
 * 用户更新站点文件夹
 * @route POST /site/folder/update
 * @group 站点文件夹管理
 * @param {UpdateFolder.model} updateFolder.body.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @security JWT
 */
router.post('/update', auth(), handlerValidate(siteFolderController.updateFolder))

/**
 * 用户更新站点文件夹排序
 * @route POST /site/folder/sort
 * @group 站点文件夹管理
 * @param {UpdateFolderSort.model} updateFolderSort.body.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @security JWT
 */
router.post('/sort', auth(), handlerValidate(siteFolderController.updateSort))

/**
 * 用户删除站点文件夹
 * @route POST /site/folder/delete
 * @group 站点文件夹管理
 * @param {DeleteFolder.model} deleteFolder.body.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @security JWT
 */
router.post('/delete', auth(), handlerValidate(siteFolderController.deleteFolder))

module.exports = router
